//
//  ListPersonInChargeViewController.m
//  FMS
//
//  Created by Steven on 10/12/13.
//  Copyright (c) 2013 QGSVN. All rights reserved.
//

#import "ListPersonInChargeViewController.h"

@interface ListPersonInChargeViewController ()
@end

@implementation ListPersonInChargeViewController
@synthesize delegate;
- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
        dictLanguage = [ApplicationDelegate.arrayLanguage objectAtIndex:0];
    }
    return self;
}
#pragma mark utils methods

- (void)listPersonsInCharge{
    [personsInCharge removeAllObjects];
    for (int i = 0; i < 10; i++) {
        NSMutableDictionary *person = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"AFZ %d",i],@"personName",[NSString stringWithFormat:@"%d",i],@"personId", nil];
        [personsInCharge addObject:person];
    }
    [self.tableView reloadData];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    personsInCharge = [[NSMutableArray alloc] init];
    
    [self listPersonsInCharge];
    if ([personsInCharge count] * 44 > 480) {
        [self setContentSizeForViewInPopover:CGSizeMake(320, 480)];
    }
    else
        [self setContentSizeForViewInPopover:CGSizeMake(320, [personsInCharge count] * 44)];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [personsInCharge count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        cell.textLabel.font = [UIFont fontWithName:FMS_REGULAR_FONT size:15];
        cell.textLabel.textColor = FMS_COLOR_DEFAUL;
        
    }
    NSMutableDictionary *person = [personsInCharge objectAtIndex:indexPath.row];
    cell.textLabel.text = [person objectForKey:@"personName"];
    // Configure the cell...
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if ([delegate respondsToSelector:@selector(didSelectPersonInCharge:)]) {
        NSMutableDictionary *person = [personsInCharge objectAtIndex:indexPath.row];
        [delegate didSelectPersonInCharge:person];
    }
}
@end
